package mysqlxa;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author: admin
 * @Description:
 * @Date: 2018/11/27 17:47
 */

public class Atlas {
    public static void main(String[] args) throws SQLException {
        Connection conn=ConnectionFactory.getConnection("192.168.0.201","demo","root","123456",1234);
        //Connection conn = ConnectionFactory.getConnection("39.106.17.245", "hiddent_call_business", "root", "qj12345678@", 1234);
        Statement statement = conn.createStatement();
        for (int i = 0; i < 1000; i++) {
            //String sql="insert into user (name) values ('name"+i+"')";
            //statement.executeUpdate(sql);
            //statement.executeQuery("select * from user where id="+i);
            ResultSet resultSet = statement.executeQuery("select * from user where id=" + i);
            //statement.execute("insert into user (name) values ('name" + i+"')");
            System.out.println(resultSet.toString());
        }
//        for (int i=0; i<100;i++){
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    Connection conn = null;
//                    try {
//                        conn = ConnectionFactory.getConnection("39.106.17.245", "hiddent_call_business", "root", "qj12345678@", 1234);
//
//                        Statement statement = conn.createStatement();
//                        for (int i = 0; i < 100; i++) {
//                            //String sql="insert into user (name) values ('name"+i+"')";
//                            //statement.executeUpdate(sql);
//                            //statement.executeQuery("select * from user where id="+i);
//                            //ResultSet resultSet = statement.executeQuery("select * from business_info_user where id=" + i);
//                            //System.out.println(resultSet.toString());
//                            Boolean insert= statement.execute("insert into sys_log_message (message_body) values ('message"+i+"')");
//                            System.out.println(insert);
//                            Thread.sleep(100);
//                        }
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                    finally {
//                        if(conn!=null) {
//                            try {
//                                conn.close();
//                            } catch (SQLException e) {
//                                e.printStackTrace();
//                            }
//                        }
//                    }
//                }
//            }).start();
//        }
    }

    protected class ReadThread implements Runnable {

        @Override
        public void run() {
            Connection conn = null;
            try {
                conn = ConnectionFactory.getConnection("39.106.17.245", "hiddent_call_business", "root", "qj12345678@", 1234);

                Statement statement = conn.createStatement();
                for (int i = 0; i < 100; i++) {
                    //String sql="insert into user (name) values ('name"+i+"')";
                    //statement.executeUpdate(sql);
                    //statement.executeQuery("select * from user where id="+i);
                    ResultSet resultSet = statement.executeQuery("select * from business_info_user where id=" + i);
                    System.out.println(resultSet.toString());
                    Thread.sleep(100);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            finally {
                if(conn!=null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
